﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace VNPT.Utility.Grid
{
   public partial class GridExport
    {
       public void Export(Control.MyGridControl myGridControl)
       {
           using (SaveFileDialog saveDialog = new SaveFileDialog())
           {
               saveDialog.Filter = "Excel (2003)(.xls)|*.xls|Excel (2010) (.xlsx)|*.xlsx |RichText File (.rtf)|*.rtf |Pdf File (.pdf)|*.pdf |Html File (.html)|*.html";
               if (saveDialog.ShowDialog() != DialogResult.Cancel)
               {
                   string exportFilePath = saveDialog.FileName;
                   string fileExtenstion = new FileInfo(exportFilePath).Extension;
                   switch (fileExtenstion)
                   {
                       case ".xls":
                           myGridControl.ExportToXls(exportFilePath, new DevExpress.XtraPrinting.XlsExportOptions()
                           {
                               TextExportMode = DevExpress.XtraPrinting.TextExportMode.Text,
                              // RawDataMode = true
                           }
                               );
                           break;
                       case ".xlsx":
                           myGridControl.ExportToXlsx(exportFilePath);
                           break;
                       case ".rtf":
                           myGridControl.ExportToRtf(exportFilePath);
                           break;
                       case ".pdf":
                           myGridControl.ExportToPdf(exportFilePath);
                           break;
                       case ".html":
                           myGridControl.ExportToHtml(exportFilePath);
                           break;
                       case ".mht":
                           myGridControl.ExportToMht(exportFilePath);
                           break;
                       default:
                           break;
                   }

               }
           }
       }
    }
}
